#!/usr/bin/perl -w

 # Determining whether a given string is a palindrome
 # (Iterative approach)

 sub isPalindrome($);

 print "Enter a string > ";
 chomp(my $str = <STDIN>);
 if ($str ne "") {
 print "$str is ", isPalindrome($str)?"":"not ", "a palindrome.\n";
 } else {
 print "The string should not be empty!\n";
 }

 sub isPalindrome($) {
 my $string = $_[0];

 my $ctr_l = 0;
 my $ctr_r = length($string)-1;

 while ($ctr_l <= $ctr_r) {
 # To do case-insensitive comparison, convert both to lowercase if applicable
 my $leftchar = lc substr($string, $ctr_l, 1);
 my $rightchar = lc substr($string, $ctr_r, 1);
 if ($leftchar ne $rightchar) {
 return 0;
 } else {
 $ctr_l++;
 $ctr_r--;
 }
 }
 return 1;
 }